package com.szyt.basicframe.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Value("${enableSwagger}")
    private Boolean enableSwagger;

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())

                //为false不能在浏览器访问 " Could not render e, see the console."
                .enable(enableSwagger)
                .select()
                //指定扫描包
                .apis(RequestHandlerSelectors.basePackage("com.szyt.basicframe.controller"))
                //路径过滤
                .paths(PathSelectors.any())
                .build()
                ;
    }

    private ApiInfo getApiInfo() {
        Contact contact = new Contact("", "", "");
        return new ApiInfo(
                "1503的Swagger API文档",
                "Api Documentation描述",
                "1.0",
                "https://blog.csdn.net/qq_36762765",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>());
    }
}
